import os

from libs.MySqlUtil import MySqlUtil
from libs.Objects import Objects


class CleanData(object):
    def __init__(self):
        self.conn = MySqlUtil(**MySqlUtil.CONF)
        print(self.conn.get_dicts("SELECT VERSION()"))

    def deleteDB(self, date):
        self.deleteHotReview(date)
        self.deleteTradingEmotion(date)

    def deleteHotReview(self, date):
        sql = ("delete from hot_review where day='{date}'".format(date=Objects.to_db_date(date)))
        return self.conn.execute(sql)

    def deleteTradingEmotion(self, date):
        sql = ("delete from trading_emotion where day='{date}'".format(date=Objects.to_db_date(date)))
        return self.conn.execute(sql)

    def deleteCSV(self, date):
        all_files = Objects.getAllFile(dir_path='../data/trading')
        for file in all_files:
            if file.endswith("%s.csv" % (date)):
                os.remove(file)


if __name__ == '__main__':
    a = CleanData()
    a.deleteDB('2025-04-21')
